package customerEnter.Frame.Utils;

import java.util.ArrayList;
import java.util.List;

import customerEnter.tool.WhetherToEmpty;

/**
 * 
 * 类描述： 把地址轉換成ASCII
 * 
 * 类名称：UrlEncryptionUtils
 * 
 * 创建人：dy
 * 
 * 创建时间：2017-8-15 下午3:38:03
 * 
 */
public class UrlEncryptionUtils {

	public static int[] string2ASCII(String s) {
		if (s == null || "".equals(s)) {
			return null;
		}

		char[] chars = s.toCharArray();
		int[] asciiArray = new int[chars.length];

		for (int i = 0; i < chars.length; i++) {
			asciiArray[i] = char2ASCII(chars[i]);
		}
		return asciiArray;
	}

	public static int char2ASCII(char c) {
		return (int) c;
	}

	public static String exChange(String str) {
		return str.toLowerCase();
	}

	public static String replaceEN(String str) {
		for (int i = 0, k = 97; i < 10 && k < 107; i++, k++) {
			char ch = (char) k;
			str = str.replace("" + i + "", "" + ch);
		}
		return str;
	}

	@SuppressWarnings("unused")
	private String replacePeculiar(String str) {
		for (int i = 0; i < 10; i++) {
			if (i == 0) {
				str = str.replace(Integer.toString(i), "∝");
			} else if (i == 1) {
				str = str.replace(Integer.toString(i), "∽");
			} else if (i == 2) {
				str = str.replace(Integer.toString(i), "∈");
			} else if (i == 3) {
				str = str.replace(Integer.toString(i), "∞");
			} else if (i == 4) {
				str = str.replace(Integer.toString(i), "≌");
			} else if (i == 5) {
				str = str.replace(Integer.toString(i), "∉");
			} else if (i == 6) {
				str = str.replace(Integer.toString(i), "∥");
			} else if (i == 7) {
				str = str.replace(Integer.toString(i), "∬");
			} else if (i == 8) {
				str = str.replace(Integer.toString(i), "∭");
			} else if (i == 9) {
				str = str.replace(Integer.toString(i), "∂");
			}
		}
		return str;
	}

	public static String IcyDecrypt(String str) {
		List<String> list = new ArrayList<String>();
		for (int i = 0; i < str.length(); i = i + 6) {
			int k = i + 6;
			String sub = str.substring(i, k);
			list.add(sub);
		}
		str = "";
		int su = 1;
		for (String string : list) {
			String[] sub2 = string.split("");
			String ss = "";
			int in = 0;
			for (int j = 0; j < sub2.length; j++) {
				if (j < sub2.length) {
					String strs2 = sub2[j];
					if (!"0".equals(strs2) && !WhetherToEmpty.StringWhetherToEmpty(strs2)) {
						in = j;
						break;
					}
				}
			}
			for (int j = 0; j < sub2.length; j++) {
				if (j >= in) {
					ss += sub2[j];
				}
			}
			// String ss = "002002";
			if (su == 10000) {
				su = 1;
			}
			int d = Integer.parseInt(ss) - su;

			su++;
			char e = (char) d;
			String sst = e + "";
			if ("∝".equals(sst)) {
				sst = 0 + "";
			}
			if ("∽".equals(sst)) {
				sst = 1 + "";
			}
			if ("∈".equals(sst)) {
				sst = 2 + "";
			}
			if ("∞".equals(sst)) {
				sst = 3 + "";
			}
			if ("≌".equals(sst)) {
				sst = 4 + "";
			}
			if ("∉".equals(sst)) {
				sst = 5 + "";
			}
			if ("∥".equals(sst)) {
				sst = 6 + "";
			}
			if ("∬".equals(sst)) {
				sst = 7 + "";
			}
			if ("∭".equals(sst)) {
				sst = 8 + "";
			}
			if ("∂".equals(sst)) {
				sst = 9 + "";
			}
			str += sst;
		}

		return str;
	}
}
